<layout name="Layout/layout" />


<form action="{:U('Admin/Role/add')}" method="post" class="form-horizontal" role="form">
    <!-- #section:elements.form -->

    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right" for="role_name"> 角色名称 </label>

        <div class="col-sm-9">
            <input type="text" id="role_name" name="role_name" value="" placeholder="" class="col-xs-10 col-sm-5" />
        </div>
    </div>


    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right" for="tab"> 选择权限</label>
        <div class="col-sm-9">
            <table id="tab" class="table table-striped table-bordered table-hover">
                <volist name="pridata" id="p">
                    <eq name="p.level" value="1">
                    <tr>
                        <td class="col-sm-2">
                            <span>
                                <input id="c{$p.id}" name="pri_id[]" value="{$p.id}" onclick="check({$p.id})" class="ace ace-checkbox-2" type="checkbox">
                                <span class="lbl">{$p.pri_name}</span>
                            </span>
                        </td>
                        <td>
                            <volist name="pridata" id="r">
                                <eq name="r.parent_id" value="$p.id">
                                    <span style="display: inline-block;margin-right: 10px;">
                                        <input name="pri_id[]" value="{$r.id}" level="{$p.id}" class="ace ace-checkbox-2" type="checkbox">
                                        <span class="lbl">{$r.pri_name}</span>
                                    </span>

                                    <volist name="pridata" id="i">
                                        <eq name="i.parent_id" value="$r.id">
                                            <span style="display: inline-block;margin-right: 10px;">
                                                <input name="pri_id[]" value="{$i.id}" level="{$p.id}" class="ace ace-checkbox-2" type="checkbox">
                                                <span class="lbl">{$i.pri_name}</span>
                                            </span>
                                        </eq>
                                    </volist>
                                </eq>
                            </volist>
                        </td>
                    </tr>
                    </eq>
                </volist>
            </table>
        </div>
    </div>


    <div class="clearfix form-actions">
        <div class="col-md-offset-3 col-md-9">
            <button class="btn btn-info" type="submit">
                <i class="ace-icon fa fa-check bigger-110"></i>
                提交
            </button>

        </div>
    </div>

</form>

<script>
    function check(id){
        var allprev = $(":checkbox");
        if($("#c"+id).is(':checked')){
            $(allprev).each(function(k,v){
                // 判断是不是下级的权限
                if($(v).attr("level") == id && !$(v).is(':checked'))
                {
                    $(v).click();
                }
            });
        }else{
            $(allprev).each(function(k,v){
                // 判断是不是下级的权限
                if($(v).attr("level") == id && $(v).is(':checked'))
                {
                    $(v).click();
                }
            });
        }
    }
</script>